package trab4.transactions;

import trab4.*;
import trab4.rpc.* ;
import trab4.transactions.two_phase_commit.*;

// TODO: Implement here the transaction manager for Distributed Transactions...
// Also implement here the 2PC protocol...
public class dTransactionManager<T> extends cTransactionManager<T> implements TwoPhaseCommit {
	
	public dTransactionManager( Server owner ) {
		super( owner ) ;
	}

	public long d_OpenTransaction() 
	{
/*		long tid = tidCounter++;

		Transactions[] cts = new ClientTransactionStub[ServerDB.size()];

		TGridOperations[] tops = new TGridOperations[ ServerDB.size() ] ;
		for( int i = 0 ; i < tops.length ; i++ )
			tops[i] = Naming.lookupServer( this, "//" + i  ) ;		

		long tid = tops[0].d_OpenTransaction()  ;

		
		/*
		System.err.println("Not properly implemented...") ; 
		
		try {
			int otherSid = ( owner.sid + 1 ) % ServerDB.size();
			// Test of a 2pc rpc invocation...to a DIFFERENT server...
			TwoPhaseCommit x = Naming.lookupServer( owner, "//" + otherSid + "/2pc" ) ;
			x.tpc_op1() ;		
		} finally{}
		return c_OpenTransaction() ;  /**/
		
//		return tid;
		return 0;
	} 
	
	public long d_OpenLocalTransaction()
	{
		return 0;
	}
	
	
	public TransactionResult d_CloseTransaction( long tid) {
		System.err.println("Not properly implemented...") ; 
		return c_CloseTransaction( tid ) ;
	}

	public void tpc_op1() {
		System.err.println("2PC Operation...Not implemented...") ;
		// TODO Auto-generated method stub
	}

	public <Q> Q tpc_op2() {
		System.err.println("2PC Operation...Not implemented...") ;
		// TODO Auto-generated method stub
		return (Q)null;
	}
}